import { createRouter, createWebHashHistory } from 'vue-router';
import News from '../views/News.vue';
import New from '../views/New.vue';
import Product from '../views/Product.vue';
import NProgress from 'nprogress';

import 'nprogress/nprogress.css';
const routes = [
    {
        path: '/',
        name: 'news',
        component: News,
    },
    {
        path: '/new/:id',
        name: 'new',
        component: New,
    },
    {
        path: '/product',
        name: 'product',
        component: Product,
    },
];

const router = createRouter({
    history: createWebHashHistory(),
    routes,
});
//路由拦截器--前置的钩子 执行前
router.beforeEach((to, from, next) => {
    //每次切换执行
    NProgress.start();
    next();
});
//路由拦截器--后置的钩子 执行后
router.afterEach((to, from, next) => {
    //路由切换完毕执行结束
    NProgress.done();
});
export default router;
